using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.ComponentModel;
using System.Drawing;
using MacomberMap.Common.Types;
using System.Data.Common;

namespace MacomberMap.Common.User_Interfaces.Components
{
    /// <summary>
    /// This class covers the parameters by which a particular type is displayed
    /// </summary>
    public class MM_Display_Parameter : MM_Serializable
    {
        #region Variable declarations
        /// <summary>The foreground color to display this event</summary>
        [Category("Display"), Description("The foreground color of the item")]
        public Color Color
        {
            get { return _ForeColor; }
            set { _ForeColor = value; }
        }

        private Color _ForeColor;

        /// <summary>The foreground color to display this event</summary>
        [Category("Display"), Description("The foreground color of the item")]
        public Color ForeColor
        {
            get { return _ForeColor; }
            set { _ForeColor = value; }
        }

        /// <summary>The foreground color to display this event</summary>
        [Category("Display"), Description("The foreground pen (color & width) of the item")]
        public Pen ForePen
        {
            get { return new Pen(_ForeColor, _Thickness); }
        }

        private float _Thickness = 1f;

        /// <summary>When drawing a substation or line of this type, what width/size should be shown</summary>
        [Category("Display"), Description("The width of the item on a line or substation, or font weight"), DefaultValue(1f)]
        public float Thickness
        {
            get { return _Thickness; }
            set { _Thickness = value; }
        }

        /// <summary>When drawing a substation or line of this type, what width/size should be shown</summary>
        [Category("Display"), Description("The width of the item on a line or substation, or font weight"), DefaultValue(1f)]
        public float Width
        {
            get { return _Thickness; }
            set { _Thickness = value; }
        }

        private bool _Blink = false;
        /// <summary>When drawing a substation or line of this type, should it blink?</summary>        
        [Category("Display"), Description("Whether this display parameter should blink between itself and another"), DefaultValue(false)]
        public bool Blink
        {
            get { return _Blink; }
            set { _Blink = value; }
        }


        /// <summary>Whether the user is permitted to see these Events</summary>
        public bool Permitted;

        #endregion

        #region Initialization
        /// <summary>
        /// Initialize the display parameter
        /// </summary>
        /// <param name="ElementSource">The XML element containing the parameter's information</param>        
        public MM_Display_Parameter(XmlElement ElementSource)
            : base(ElementSource)
        {
            if (ElementSource.HasAttribute("Permitted"))
                this.Permitted = XmlConvert.ToBoolean(ElementSource.Attributes["Permitted"].Value);
            else
                this.Permitted = true;
        }

        /// <summary>
        /// Initialize the display parameter
        /// </summary>
        /// <param name="ElementSource">The XML element containing the parameter's information</param>   
        /// <param name="Prefix"></param>
        public MM_Display_Parameter(XmlElement ElementSource, String Prefix)
            : base(ElementSource, Prefix)
        {
            if (ElementSource.HasAttribute(Prefix + ".Permitted"))
                this.Permitted = XmlConvert.ToBoolean(ElementSource.Attributes[Prefix + ".Permitted"].Value);
            else
                this.Permitted = true;
        }


        /// <summary>
        /// Initialize the display parameter
        /// </summary>
        /// <param name="dbReader">The data reader containing the parameter's information</param>
        public MM_Display_Parameter(DbDataReader dbReader) : base(dbReader) { }

        /// <summary>
        /// Initialize a display parameter by color and thickness
        /// </summary>
        /// <param name="ForeColor">The foreground color of the line</param>
        /// <param name="Thickness">The thickness of the line</param>
        /// <param name="Blinking">Whether the parameter is blinking</param>
        public MM_Display_Parameter(Color ForeColor, float Thickness, bool Blinking)
        {
            this.Permitted = true;
            this.ForeColor = ForeColor;
            this.Thickness = Thickness;
            this.Blink = true;
        }

        /*// <summary>
        /// Reinitialize the display parameters for this element
        /// </summary>
        /// <param name="xE"></param>
        public void ReinitializeDisplay(XmlElement ElementSource, Data_Integration IntegrationLayer)
        {
            base.ReadXML(ElementSource, IntegrationLayer);
           
            this.Width = MM_Converter.ToSingle(xE.Attributes["Width"].Value);
            this.Blink = XmlConvert.ToBoolean(xE.Attributes["Blink"].Value.ToLower());
            
            //First, try to see whether the specified color is a known color

            ForeColor = System.Drawing.ColorTranslator.FromHtml(xE.Attributes["Color"].Value);              
        }*/
        #endregion


    }
}
